const $utils = {
  urlQuery: function(name) {
    let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
    let r = window.location.search.substr(1).match(reg)
    if (r != null) {
      return unescape(r[2])
    }
    return null
  },
  qsStringify: function(data) {
    let ret = ''
    for (let it in data) {
      ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
    }
    return ret.slice(0, -1)
  },
  StrQuery: function(urlStr, key) {
    if (urlStr) {
      let obj = {}
      let arr1 = urlStr.split('&')
      if (arr1.length) {
        for (let i = 0; i < arr1.length; i++) {
          let arr2 = arr1[i].split('=')
          obj[arr2[0]] = arr2[1]
        }
      }
      if (key) {
        return obj[key]
      }
      return obj
    }
  },
}

export default $utils
